<template>
  <div class="overview" v-loading="loading">
    <div class="overview-data">
      <div v-for="item in overViewData" :key="item.label" class="data-box">
        <div class="label">{{ item.label }}</div>
        <div class="total">{{ item.total.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') }}</div>
        <div class="today">今日 {{ item.todayCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') }}</div>
        <div class="yesterday">昨日 {{ item.yesterdayCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') }}</div>
      </div>
    </div>
    <el-row :gutter="20" class="overview-chart">
      <el-col :span="12">
        <div class="el-card">
          <PageView />
        </div>
      </el-col>
      <el-col :span="12">
        <div class="el-card">
          <AreaView :params="params" />
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
/* eslint-disable */
import { ref, onBeforeMount } from 'vue'
import PageView from './components/PageView'
import AreaView from './components/AreaView'
import { getStationOverview } from '@/api/log'
import { useStore } from 'vuex'

const store = useStore()
const siteId = ref(store.state.site.currentSite?.id)
const loading = ref(false)
const overViewData = ref()
const init = async () => {
  try {
    loading.value = true
    const res = await getStationOverview({ siteId: siteId.value })
    if (res.code === 20000) {
      overViewData.value = res.data
    }
  } catch {
    loading.value = false
  }
  loading.value = false
}

onBeforeMount(() => {
  init()
})
</script>

<style lang="scss" scoped>
.overview {
  padding: 0 20px;
  .overview-data {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
    padding: 24px;
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 40px;

    .data-box {
      flex: 1;
      min-width: 200px;
      position: relative;
      
      &:not(:last-child)::after {
        content: '';
        position: absolute;
        right: -20px;
        top: 0;
        bottom: 0;
        width: 1px;
        background: #f0f0f0;
      }

      .label {
        font-size: 14px;
        color: #909399;
        margin-bottom: 12px;
      }

      .total {
        font-size: 36px;
        font-weight: bold;
        color: #303133;
        line-height: 1.2;
        margin-bottom: 16px;
      }

      .today,
      .yesterday {
        font-size: 13px;
        color: #606266;
        margin-bottom: 8px;

        &:last-child {
          margin-bottom: 0;
        }
      }
    }
  }

  // 图表区域
  .overview-chart {
    .el-col {
      .el-card {
        background: #fff;
        border-radius: 8px;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
        padding: 4px;
      }

      :deep(.echarts) {
        min-height: 400px;
      }
    }
  }
}

// 响应式处理
@media screen and (max-width: 768px) {
  .overview {
    padding: 12px;

    .overview-data {
      padding: 20px;
      gap: 24px;

      .data-box {
        &:not(:last-child)::after {
          display: none;
        }

        .total {
          font-size: 28px;
        }
      }
    }

    .overview-chart {
      .el-col {
        margin-bottom: 20px;

        &:last-child {
          margin-bottom: 0;
        }

        .el-card {
          padding: 16px;
        }

        :deep(.echarts) {
          min-height: 300px;
        }
      }
    }
  }
}
</style>
